import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";

/** 统一的timePeriod处理方法，将时间戳格式化到秒的形式 */
export const formatTimePeriod = (timePeriod: Array<number>) => {
  return {
    startTime: Math.floor(timePeriod[0] / 1000),
    endTime: Math.floor(timePeriod[1] / 1000)
  };
};

export const getStatsData = (timePeriod: Array<number>) => {
  return http.request<any>("get", baseUrlApi("datacenter/statscards"), {
    params: formatTimePeriod(timePeriod)
  });
};

export const getSalesmanData = (timePeriod: Array<number>) => {
  return http.request<any>("get", baseUrlApi("datacenter/salesman"), {
    params: formatTimePeriod(timePeriod)
  });
};

export const getSalesmanOrderAmountDistribution = (
  timePeriod: Array<number>
) => {
  return http.request<any>(
    "get",
    baseUrlApi("datacenter/salesmanAmountDistribution"),
    {
      params: formatTimePeriod(timePeriod)
    }
  );
};
export const getPurchaseUnitData = (timePeriod: Array<number>) => {
  return http.request<any>("get", baseUrlApi("datacenter/purchasingUnit"), {
    params: formatTimePeriod(timePeriod)
  });
};

export const getPurchaseUnitOrderAmountDistribution = (
  timePeriod: Array<number>
) => {
  return http.request<any>(
    "get",
    baseUrlApi("datacenter/purchasingUnitAmountDistribution"),
    {
      params: formatTimePeriod(timePeriod)
    }
  );
};
export const getBrandDistribution = (timePeriod: Array<number>) => {
  return http.request<any>("get", baseUrlApi("datacenter/brandDistribution"), {
    params: formatTimePeriod(timePeriod)
  });
};

export const getBrandOrderAmountDistribution = (timePeriod: Array<number>) => {
  return http.request<any>(
    "get",
    baseUrlApi("datacenter/brandOrderAmountDistribution"),
    {
      params: formatTimePeriod(timePeriod)
    }
  );
};

export const getSupplierData = (timePeriod: Array<number>) => {
  return http.request<any>(
    "get",
    baseUrlApi("datacenter/supplierDistribution"),
    {
      params: formatTimePeriod(timePeriod)
    }
  );
};

export const getSupplierOrderAmountDistribution = (
  timePeriod: Array<number>
) => {
  return http.request<any>(
    "get",
    baseUrlApi("datacenter/supplierOrderAmountDistribution"),
    {
      params: formatTimePeriod(timePeriod)
    }
  );
};
